

def DictBase():

    dict1 = {'name': "xiaom"}
    print(id(dict1))
    print(dict1['name'])    #取值

    dict1['age'] = 18  #增加 age
    print('#' * 50)
    print(dict1)

    dict1["name"] = "xiaomplus" #修改
    print('#' * 50)
    print(dict1)

    del dict1["name"]   # 删除
    # dict1.pop("name")
    print(dict1)

    print(len(dict1))        # 字典长度

    dict2 = {"height": 1.75,
                "age": 20}
    dict1.update(dict2)      # 合并
    print('#' * 50)
    print(dict1)
    dict1.clear()   #清空
    print('#' * 50)
    print(dict1)
    # print('#' * 50)

def TraversalDict():

    dict1 = {'name': "xiaom",
              'qq': "1008611",
            'phone': "976023"}

    for i in dict1:             # 遍历字典
        print(i, dict1[i])      #键和值一起拿
    print('#' * 50)
    for i,j in dict1.items():     #键和值分别拿
        print(f'键 {i},值 {j}')
    print('#' * 50)
    for i in dict1.keys():       #只拿到键值
        print(i)
    print('#' * 50)
    for j in dict1.values():     #只拿到 数值
        print(j)


def DictList():

    list1 = [
        {'name': 'xm',
         'qq': "12323",
         'phone': "10086"},
        {'name': 'dm',
         'qq': '190909',
         'phone': '1008611'},
        {
            'name': 'xxm',
            'qq': '98765f4',
            'phone': '1000000'
        }
    ]

    for card in list1:
        print(card)

if __name__ == '__main__':
    # TraversalDict()
    DictList()
